package spider.cluster.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import spider.zookeeper.monitor.ClusterMonitor;
import spider.zookeeper.node.Node;

import java.util.List;

/**
 * ClusterController
 *
 * @author Archx[archx@foxmail.com]
 * @date 2017/4/9.
 */
@Controller
public class IndexController {

    private ClusterMonitor monitor;

    @RequestMapping("/")
    public String index(Model model) {
        model.addAttribute("title", "Spider Cluster");

        List<Node> nodes = monitor.getAliveServers();
        model.addAttribute("nodes", nodes);
        return "index";
    }

    @Autowired
    public void setMonitor(ClusterMonitor monitor) {
        this.monitor = monitor;
    }
}
